'use strict';

module.exports = app => {
  const { STRING, INTEGER, DATE, DECIMAL } = app.Sequelize;

  const Product = app.model.define('product', {
    id: STRING(16), // 产品url sha1码为ID
    product_name: STRING(256),
    product_url: STRING(256),
    product_img: STRING(256), // 商品图片
    price_amazon: STRING(64), // 商品价格
    product_price: DECIMAL(10, 2),
    product_reviews: INTEGER(8), // 产品评论数
    product_rating: DECIMAL(2, 1), // 产品评价
    cate_top: STRING(64), // 商品主分类 如：‘sport’，‘clothing’
    month_sales: INTEGER(11), // 月度销售金额
    rank_top: INTEGER(11), // 在主分类中的排名
    cate_ref: app.Sequelize.JSON, // 商品分类，多个为数组 如：['sport','sport > t-shirt > men']
    bestsellers_rank: app.Sequelize.JSON, // 销售排名 多个为数组，如：[{catelog:'sport',rank:'1'},{'catelog':'sport > t-shirt > men',rank:'2'}]
    newreleases_rank: app.Sequelize.JSON, // 新品排名,rank数组 如： [{catelog:'sport',rank:'1'},{'catelog':'sport > t-shirt > men',rank:'2'}]
    movers_rank: app.Sequelize.JSON, // # 增长排名,rank数组 如： [{catelog:'sport',rank:'1'},{'catelog':'sport > t-shirt > men',rank:'2'}]
    created_at: { type: DATE, defaultValue: app.Sequelize.NOW },
    updated_at: { type: DATE, defaultValue: app.Sequelize.NOW },
    crawled_at: { type: DATE, defaultValue: app.Sequelize.NOW },
  });

  //   User.findByLogin = async login => {
  //     return await this.findOne({
  //       where: {
  //         login,
  //       },
  //     });
  //   };

  //   User.prototype.logSignin = async () => {
  //     return await this.update({ last_sign_in_at: new Date() });
  //   };

  return Product;
};
